#pragma once
#include "texture.h"

namespace krryn{
namespace system_imp{
	class texture_software : public view::texture{
	public:
		texture_software(view::canvas *a_Canvas, size_t a_TextureUnit) : texture(a_Canvas, a_TextureUnit){
			std::list<view::canvas *> l_MipMaps = a_Canvas->generate_mip_maps(view::canvas::scale_linear);

			m_Levels = (int)l_MipMaps.size();
			m_MipMaps = new view::canvas*[m_Levels];

			std::list<view::canvas*>::iterator i = l_MipMaps.begin();
			std::list<view::canvas*>::iterator l_End = l_MipMaps.end();

			/// put items in array for O(1) access time
			for(int n = 0; i != l_End; ++i, n++){
				m_MipMaps[n] = *i;
			}
		}

		virtual ~texture_software(){
			for(int i = 0; i < m_Levels; i++){
				delete m_MipMaps[i];
			}

			delete[] m_MipMaps;
		}

		view::canvas *get_canvas_at(int a_MipMapLevel){
			if(a_MipMapLevel >= m_Levels){
				a_MipMapLevel = m_Levels - 1;
			}else if(a_MipMapLevel < 0){
				a_MipMapLevel = 0;
			}

			return m_MipMaps[a_MipMapLevel];
		}

		virtual void enable() {}
		virtual void disable() {}

	private:
		int m_Levels;
		view::canvas **m_MipMaps;
	};
}
}